package com.fwtai.controller.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.service.web.StoreAreaService;
import com.fwtai.tool.ToolClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 门店管理控制层|路由层
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @Email service@fwtai.com
 * @创建日期 2023-09-20 17:10:29
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@RequestMapping("/storeArea")
public class StoreAreaController{

  private final StoreAreaService storeAreaService;

  public StoreAreaController(final StoreAreaService storeAreaService){
    this.storeAreaService = storeAreaService;
  }

  /**获取区代用户*/
  @PreAuthorize("hasAuthority('store_area_row_get_user')")
  @GetMapping("/listAreaUsers")
  public void listAreaUsers(final String word,final HttpServletResponse response){
    ToolClient.responseJson(storeAreaService.listAreaUsers(word),response);
  }

  /**换绑*/
  @PreAuthorize("hasAuthority('store_area_row_edit')")
  @PostMapping("/edit")
  public void delById(final Long userId,final Long target,final HttpServletResponse response){
    ToolClient.responseJson(storeAreaService.edit(userId,target),response);
  }

  /**获取数据*/
  @PreAuthorize("hasAuthority('store_area_btn_listData')")
  @GetMapping("/listData")
  public void listData(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(storeAreaService.listData(new PageFormData(request)),response);
  }
}